package com.egao.common.manage.school;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.company.entity.MutualInvitation;
import com.egao.common.module.company.service.MutualInvitationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @author lym
 * @date 2024/1/2 13:36
 */
@Api(tags = "学校双选会邀请函管理")
@RestController
@RequestMapping("${api}")
public class SchoolMutualInvitationController extends BaseController {

    @Autowired
    private MutualInvitationService mutualInvitationService;

    @PreAuthorize("hasAuthority('school:mutual-invitation:list')")
    @ApiOperation(value = "双选会邀请函信息", notes = "创建时间倒序")
    @ApiPageParam
    @GetMapping("/school/mutual-invitation/page")
    public PageResult<MutualInvitation> page(HttpServletRequest request) {
        PageParam<MutualInvitation> pageParam = new PageParam<>(request);
        return new PageResult<>(mutualInvitationService.listPage(pageParam), pageParam.getTotal());
    }

    @PreAuthorize("hasAuthority('school:mutual-invitation:save')")
    @OperLog(value = "添加双选会邀请函信息", desc = "添加双选会邀请函信息", result = true)
    @ApiOperation(value = "添加双选会邀请函信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "MutualInvitation", value = "MutualInvitation", required = true, dataType = "MutualInvitation")
    })
    @PostMapping("/school/mutual-invitation/save")
    public JsonResult save(@Valid @RequestBody MutualInvitation mutualInvitation) {
        mutualInvitation.setCreateBy(getLoginUserId());
        return mutualInvitationService.saveMutualInvitation(mutualInvitation);
    }

    @PreAuthorize("hasAuthority('school:mutual-invitation:update')")
    @OperLog(value = "修改双选会邀请函信息", desc = "修改双选会邀请函信息", result = true)
    @ApiOperation(value = "修改双选会邀请函信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "MutualInvitation", value = "MutualInvitation", required = true, dataType = "MutualInvitation")
    })
    @PutMapping("/school/mutual-invitation/update")
    public JsonResult update(@Valid @RequestBody MutualInvitation mutualInvitation) {
        return mutualInvitationService.updateMutualInvitation(mutualInvitation);
    }

    @PreAuthorize("hasAuthority('school:mutual-invitation:delete')")
    @OperLog(value = "删除双选会邀请函信息", desc = "删除双选会邀请函信息", result = true)
    @ApiOperation(value = "删除双选会邀请函信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "MutualInvitation", value = "MutualInvitation", required = true, dataType = "MutualInvitation")
    })
    @PutMapping("/school/mutual-invitation/delete")
    public JsonResult deleteMutual(@RequestBody MutualInvitation mutualInvitation) {
        return mutualInvitationService.deleteMutualInvitation(mutualInvitation);
    }



    @PreAuthorize("hasAuthority('school:mutual-invitation:list')")
    @ApiOperation(value = "获取双选会邀请函信息详情")
    @OperLog(value = "获取双选会邀请函信息详情", desc = "获取双选会邀请函信息详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "双选会邀请函信息id", required = true, dataType = "int")
    })
    @GetMapping("/school/mutual-invitation/detail")
    public JsonResult detail(Integer id) {
        return mutualInvitationService.detail(id);
    }
}
